import java.awt.print.Book;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@SuppressWarnings("all")
public class CollectonInterator {
    public static void main(String[] args) {
        Collection col = new ArrayList();
        col.add(new book("张三", "大三", 15.5));
        col.add(new book("王五", "初一", 15.2));
        col.add(new book("张三", "小学", 15.9));
        //System.out.println("col" + col);

        // itit
        Iterator iterator = col.iterator(); // 得到迭代器
        while (iterator.hasNext()) { // hasNext() 是 iterator 对象的方法
            Object obj =  iterator.next(); // 编译类型是obj,运行类型是取决于真正存放的类型
            //System.out.println("obj" + obj);
        }
        // 指向最后元素抛异常：iterator.next();
        // 再次遍历从第一个开始
        iterator = col.iterator();
        System.out.println(col);




    }
}
class book{
    private String name;
    private  String author;
    private double price;

    public book(String name, String author, double price) {
        this.name = name;
        this.author = author;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return "book{" +
                "name='" + name + '\'' +
                ", author='" + author + '\'' +
                ", price=" + price +
                '}';
    }
}